package FlowGraph.EdgeInfo;

import antlr.collections.AST;

//////////////////////////////////////////////////////////////////////////
//// ExceptionEdgeData
/**

@author Ivan Jeukens
@version v 0.1 15/01/2003
*/
public class ExceptionEdgeData  {

    public ExceptionEdgeData(int type, int bbstatement, AST ast, Class ex) {
        _type = type;
        _bbStatement = bbstatement;
        _ast = ast;
        _exceptionType = ex;
    }

    public static final int UNKOWN_EXCEPTION = 0;
    public static final int MC_THROWS = 1;
    public static final int MC_FIELD = 2;
    public static final int NO_MEMORY = 3;
    public static final int NEG_ARRAY = 4;
    public static final int FIELD_ACCESS = 5;
    public static final int ARRAY_ACCESS = 6;
    public static final int INDEX_BOUNDS = 7;
    public static final int CAST = 8;
    public static final int DIV = 9;
    public static final int REM = 10;
    public static final int ARRAY_STORE = 11;

    ///////////////////////////////////////////////////////////////////
    ////                        public methods                     ////

    public int getType() {
        return _type;
    }

    public int getBBStatement() {
        return _bbStatement;
    }

    public AST getAST() {
        return _ast;
    }

    public Class getExceptionType() {
        return _exceptionType;
    }
    
    public String toString() {
        return new String("Type = " + _toStringType(_type) +  
            " bbStatement = " + _bbStatement + " exception = " + 
            _exceptionType + "\n");
    }           

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////
    
    private String _toStringType(int type) {
        switch(type) {
            case MC_THROWS: return "Method Call Throws";
            case NO_MEMORY: return "Out of memory";
            case MC_FIELD: return "Memory Field access";
            case NEG_ARRAY: return "Negative size Array";
            case FIELD_ACCESS: return "Field Access";
            case ARRAY_ACCESS: return "Array access";
            case INDEX_BOUNDS: return "Array index out of bounds";
            case CAST: return "Class cast";
            case DIV: return "Division";
            case REM: return "Remainder";
            case ARRAY_STORE: return "Array Store";

            default: return "Unkown Exception Type";
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                      private variables                    ////

    private int _type;
    private int _bbStatement;
    private AST _ast;
    private Class _exceptionType;
}
